<?php
namespace haibao\cms\business\control\pc\channel\exclusive;

use haibao\cms\business\control\PublicController;
use haibao\cms\business\control\FeatureController;
use haibao\cms\model\data\FeaturePublish as FeatureModel;
class ExclusiveListController extends \haibao\cms\business\control\pc\channel\exclusive\ExclusiveController{
    
    public function __construct($updateTime = null,$controlId,$isPublish){

        parent::__construct($updateTime,$controlId,$isPublish);
    }


    /**
     * 获取模版内容
     * @param : String $content
     */
    public function displayTemplateHtml(){
        $controlData = $this->getParameter(self::$CONTROL_DATA);
        $content = $this->getParameter(self::$CONTROL_CONTENT);
        $currentPage = $this->getParameter(self::$CURRENTPAGE);
        $pageable = $this->getParameter(self::$PAGEABLE);
        $this->assign('siteTemplateId', $this->getParameter(self::$SITE_TEMPLATE_ID));
        if($controlData['manual']){
            if(!$this->isPublish){

                $this->assign('viewName','priview');
                $this->assign('pageUrl','/site/preview.html');
            }else{

                $fileName = $this->getParameter(self::$FILE_NAME);
                $this->assign('viewName','publish');
                $url = \haibao\classlibrary\cms\Config::getConfig(\haibao\classlibrary\cms\Config::CLASSLIBRARY_CONFIG_HOST_EXCLUSIVE);
                $url .= '/'.trim($fileName,'/').'/';
                $url = preg_replace('/\/channel/i','', $url);
                $this->assign('pageUrl',$url);
            }
            $path = $this->generateHtmlPath(__CLASS__,$this->conditionTagId.$currentPage);
            $dataCondition = $controlData['manual'];
            $dataCondition['currentPage'] = $currentPage;
            
            $this->getActualData($dataCondition);
            $this->assign('exclusiveDomain', \haibao\classlibrary\cms\Config::getConfig(\haibao\classlibrary\cms\Config::CLASSLIBRARY_CONFIG_HOST_EXCLUSIVE));
            $this->assign('homePage', \haibao\classlibrary\cms\Config::getConfig(\haibao\classlibrary\cms\Config::CLASSLIBRARY_CONFIG_HAIBAO_URL));
            $this->generateHtml($path,$content);
            $content = $this->getHtml($path);
            $content = $this->replaceCDNLink($content);
            return $content;
        }
    }
    
    public function getFeatureClasses(){
        return array(
            FeatureModel::CLASS_FASHION=>'潮流',
            FeatureModel::CLASS_PAINT=>'美妆',
            FeatureModel::CLASS_STAR=>'明星',
            FeatureModel::CLASS_FASHION_WEEK=>'时装周',
            FeatureModel::CLASS_BRAND=>'品牌',
			FeatureModel::CLASS_ZHIBO=>'秀场直播',
			FeatureModel::CLASS_BRAND_DINGZHI=>'品牌定制'
        );
    }
    
    private function getActualData($dataCondition){
        if($dataCondition['type'] == self::FEATURE_TYPE){
            list($result,$pager) = FeatureController::getFeaturelist(-1,$dataCondition['limit'],$dataCondition['currentPage']);
            $this->assign('siteType', self::DATA_TYPE_FEATURE);
            foreach ($result as $key=>$list){
                $list->Title = $this->cutTitle($list->FeatureDefine->FeatureName, 24);
                $list->Pic = $list->Image->Filename;
                $list->PublishTime = $this->formatDate($list->ListTime->format('Y-m-d H:i:s'));
            }
            $this->assign('featureClass', $this->getFeatureClasses());
        }elseif($dataCondition['type'] == self::VIDEO_TYPE){
        	$exclusiveObj = ExclusiveController::getExclusiveInstance();
            list($result,$pager) = PublicController::getVideolist(0,$dataCondition['limit'],$dataCondition['currentPage'],$exclusiveObj->videoId);
            $this->assign('siteType', self::DATA_TYPE_VIDEO);
            foreach ($result as $key=>$list){
                $list->Title = $this->cutTitle($list->Title, 24);
                $list->PublishDate = $this->formatDate($list->PublishDate->format('Y-m-d H:i:s'));
            }
            //$videoCategoryList = \haibao\cms\business\VideoCategory::getAllCategory();
            $videoCategoryList = array(
	    		28=>array('Id'=>28,'CategoryName'=>'明星撞衫咚咚锵'),
	    		27=>array('Id'=>27,'CategoryName'=>'潮我看齐'),
	    		26=>array('Id'=>26,'CategoryName'=>'报尚名来'),
	    		29=>array('Id'=>29,'CategoryName'=>'MUSE美丽志'),
	    		17=>array('Id'=>17,'CategoryName'=>'明星专访'),
	    		224=>array('Id'=>224,'CategoryName'=>'测呗'),
	    		225=>array('Id'=>225,'CategoryName'=>'最美的你'),
	    		226=>array('Id'=>226,'CategoryName'=>'摩范先生'),
    		);
            $this->assign('categoryList',$videoCategoryList);
        }
        
        $this->assign('pageCount',$pager->getPageCount());
        $this->assign('pager', $pager);
        $this->assign('result', $result);
    }
}